@extends('layout.master')

@section('title','游戏奖品领取记录')

@section('css')
    @parent
    <!-- Daterange picker plugins css -->
    <link href="{{ asset('plugins/bower_components/bootstrap-daterangepicker/daterangepicker.css') }}" rel="stylesheet">
@endsection
@section('main')

    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel1">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel1">拒绝理由</h4>
                </div>
                <div class="modal-body">
                    <form class="floating-labels role-edit">
                        <input id="id-edit" name="id" type="hidden" value="">
                        <fieldset style="border:0;">

                            <div class="form-group m-b-40 m-t-10">
                                <input type="text" class="form-control" id="check-content" name="check_content" required><span
                                        class="highlight"></span> <span class="bar"></span>
                                <label for="input1">理由</label>
                            </div>
                            <div class="form-actions">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="row">
                                            <div class="col-md-offset-3 col-md-9">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">取消
                                                </button>
                                                {!! csrf_field() !!}
                                                <button type="submit" class="btn btn-success" id="btn-refuse"><i
                                                            class="fa fa-check"></i> 保存
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>


    <div class="modal fade" id="agree" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel1">
        <div class="modal-dialog modal-lg" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                                aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="exampleModalLabel1">填写快递信息</h4>
                </div>
                <div class="modal-body">
                    <form class="floating-labels role-edit">
                        <input id="id-edit-agree" name="id" type="hidden" value="">
                        <fieldset style="border:0;">
                            <input type="text" class="form-control" id="name" readonly /><span
                                    class="highlight"></span>
                            <input type="text" class="form-control" id="phone" readonly><span
                                    class="highlight"></span>
                            <input type="text" class="form-control" id="address" readonly><span
                                    class="highlight"></span>
                            <div class="form-group m-b-40 m-t-10">
                                <input type="text" class="form-control" id="express-name" name="express_name" required><span
                                        class="highlight"></span> <span class="bar"></span>
                                <label for="input1">快递名称</label>
                            </div>
                            <div class="form-group m-b-40 m-t-10">
                                <input type="text" class="form-control" id="express-order" name="express_order" required><span
                                        class="highlight"></span> <span class="bar"></span>
                                <label for="input1">快递单号</label>
                            </div>
                            <div class="form-actions">
                                <div class="row">
                                    <div class="col-md-12">
                                        <div class="row">
                                            <div class="col-md-offset-3 col-md-9">
                                                <button type="button" class="btn btn-default" data-dismiss="modal">取消
                                                </button>
                                                {!! csrf_field() !!}
                                                <button type="submit" class="btn btn-success" id="btn-agree"><i
                                                            class="fa fa-check"></i> 保存
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <div class="panel">
        <div class="panel-wrapper collapse in" aria-expanded="true">
            <div class="panel-body">
                <form action="#">
                    <div class="form-body">
                        <div class="row">
                            <div class="col-xs-3 col-md-3">
                                <div class="form-group">
                                    <label for="status">状态</label>
                                    <select class="form-control column_filter"
                                            data-column="0">
                                        <option value="a">全部</option>
                                        @foreach(App\GamePrizeLog::$StatusDisplay as $key => $value)
                                            <option value="{{ $key }}">{{ $value }}</option>
                                        @endforeach
                                    </select>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <div class="panel">
        <div class="panel-heading">积分抽奖列表</div>
        <div class="panel-wrapper collapse in" aria-expanded="true">
            <div class="panel-body">
                <div class="table-responsive">
                    <table id="example23" class="display nowrap" cellspacing="0" width="100%"
                           data-url="{{ url(request()->getUri()) }}">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>用户名</th>
                            <th>游戏</th>
                            <th>奖品</th>
                            <th>收货人</th>
                            <th>联系方式</th>
                            <th>状态</th>
                            <th>订单信息</th>
                            <th>申请时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
@endsection
@section('js')
    @parent
    <!-- Plugin JavaScript -->
    <script src="{{ asset('plugins/bower_components/moment/moment.js') }}"></script>
    <!-- Date range Plugin JavaScript -->
    <script src="{{ asset('plugins/bower_components/bootstrap-daterangepicker/daterangepicker.js') }}"></script>
    <script src="{{ asset('js/myself.js') }}"></script>
    <script>
        $('.input-daterange-datepicker').daterangepicker({});
    </script>
    <script>

        $("#btn-refuse").click(function (e) {
            e.preventDefault();
            var id = $('#id-edit').val();
            var check_content = $('#check-content').val();
            swal({
                    title: "",
                    text: "确定不通过么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/game/prize/refuse/' + id,
                        data:{check_content:check_content},
                        type: 'POST',
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });

        function refuse(sid) {
            $("#id-edit").val(sid);
        }

        function agree(sid) {
            $("#id-edit-agree").val(sid);
            $.ajax({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                },
                url: '/game/prize/info/' + sid,
                type: 'POST',
                success: function (data) {
                    $("#name").val("收货人：" + data.name);
                    $("#phone").val("联系方式：" + data.phone);
                    $("#address").val("收货地址：" + data.address);
                }
            })

        }

        $("#btn-agree").click(function (e) {
            e.preventDefault();
            var id = $('#id-edit-agree').val();
            var express_name = $('#express-name').val();
            var express_order = $('#express-order').val();
            swal({
                    title: "",
                    text: "确定通过么？",
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "是的",
                    closeOnConfirm: false
                },
                function () {
                    $.ajax({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        },
                        url: '/game/prize/agree/' + id,
                        data:{express_name:express_name, express_order:express_order},
                        type: 'POST',
                        success: function (data) {
                            if (data.status !== 1) {
                                swal(data.message);
                            } else {
                                swal(data.message, '', 'success');
                                $('.confirm').click(function () {
                                    location.reload();
                                });
                            }
                        }
                    })
                }
            );
        });

    </script>
@endsection